<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="stylesheet" href="css/recognize.css">
    <link rel="stylesheet" href="css/style.css">
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://rsms.me/inter/inter.css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <!-- 设置网页图标 -->
    <link rel="icon" href="images/favicon2.gif">
    <link rel="shortcut icon" href="images/favicon2.gif">
</head>
<body>
<div class="violet-glow"></div>
<header class="blurry-navbar">
    <div class="navbar-content">
        <h1 class="text-animation text-3xl font-bold">藏药植物药知识平台</h1>
        <nav>
            <!--            <ul>-->
            <!--                <li><a href="recognize.html">图片识别</a></li>-->
            <!--                <li><a href="graph.html">知识图谱</a></li>-->
            <!--                <li><a href="database.html">数据库</a></li>-->
            <!--                <li><a href="board.html">数据显示</a></li>-->
            <!--            </ul>-->
        </nav>
    </div>
</header>

<div class="container">
    <form class="login">
        <h2>注册</h2>
        <br>
        <input type="text" placeholder="用户名" id="username">
        <br>
        <input type="password" placeholder="密码" id="password">
        <br>
        <button onclick="register()">注册</button>已经有账号了？<a href="login.html">登录</a>
    </form>
</div>

<script>
    function register() {
        event.preventDefault();  // 阻止表单默认提交行为
        $.ajax({
            type: "post",
            url: "http://localhost:8081/register",
            data: {
                username: $("#username").val(),
                password: $("#password").val()
            },
            success: function (result) {
                console.log(result);
                if(result === true) {
                    alert("注册成功!!");
                    location.href = "login.html";
                }
                else {
                    alert("用户已存在!!");
                }
            }
        })
    }
</script>

<!-- <footer class="footer">
    <div class="footer-content">
        <p>&copy; 2023 Your Company. All rights reserved.</p>
        <p>Contact: <a href="mailto:contact@example.com">contact@example.com</a></p>
    </div>
</footer> -->
</body>
</html>